package parts 
{
	import events.PartEvent;
	import flash.display.Sprite;
	import gs.easing.Cubic;
	import gs.TweenLite;
	
	/**
	 * 
	 * @author Kasoi
	 */
	public class PartBase extends Sprite
	{
		static public const CLOSED: String = 'closed';
		
		static public const OPENED: String = 'opened';
		
		static public const DESTROYED: String = 'destroyed';
		
		////////////////////////////////////////////////////////////////////
		// Public properties
		////////////////////////////////////////////////////////////////////
		
		public function get code() : String
		{
			return this._code;
		}
		
		public function get showPhase() : Number 
		{
			return this._showPhase;
		}
		
		public function set showPhase(value: Number) : void 
		{
			this._showPhase = value;
			
			this.alpha = value;
		}
		
		public function get partState() : String 
		{ 
			return this._partState; 
		}
		
		////////////////////////////////////////////////////////////////////
		// Private properties
		////////////////////////////////////////////////////////////////////
		
		protected var _code: String;
		
		protected var _showPhase: Number = 0;
		
		private var _partState: String;
		
		////////////////////////////////////////////////////////////////////
		// Public methods
		////////////////////////////////////////////////////////////////////
		
		public function PartBase() 
		{
			this.showPhase = 0;
		}
		
		public function open() : void 
		{
			TweenLite.to(this, 1.5, { showPhase: 1, ease: Cubic.easeOut,
				onComplete: this.dispatchOpened } );
		}
		
		public function close() : void 
		{
			TweenLite.to(this, 1, { showPhase: 0, ease: Cubic.easeOut,
				onComplete: this.dispatchClosed } );
		}
		
		public function resize() : void 
		{
			
		}
		
		protected function dispatchClosed() : void 
		{
			this._partState = PartBase.CLOSED;
			this.dispatchEvent(new PartEvent(PartEvent.PART_CLOSED));
		}
		
		protected function dispatchOpened() : void 
		{
			this._partState = PartBase.OPENED;
			this.dispatchEvent(new PartEvent(PartEvent.PART_OPENED));
		}
		
		protected function dispatchDestroyed() : void 
		{
			this._partState = PartBase.DESTROYED;
		}
		
		public function destroy() : void 
		{
			this.dispatchDestroyed();
		}
		
		////////////////////////////////////////////////////////////////////
		// Private methods
		////////////////////////////////////////////////////////////////////
		
		////////////////////////////////////////////////////////////////////
		// Listeners
		////////////////////////////////////////////////////////////////////
		
	}
	
}